home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10178 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news-m01.ny.us.ibm.net!usenet
  2. From: rwolf@ibm.net
  3. Newsgroups: comp.lang.c++,rb.technical
  4. Subject: Re: Can copy constructor and operator= share code?
  5. Date: 6 Mar 1996 04:19:37 GMT
  6. Organization: Rudolph Research
  7. Message-ID: <4hj3op$2ota@news-s01.ny.us.ibm.net>
  8. References: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM> <VA.00000053.00cdab05@fred> <4hdkdj$3id0@news-s01.ny.us.ibm.net> <4hhfa5$m6r@dawn.mmm.com>
  9. Reply-To: rwolf@ibm.net
  10. NNTP-Posting-Host: slip166-72-133-98.tx.us.ibm.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4hhfa5$m6r@dawn.mmm.com>, kjhopps@mmm.com (Kevin J Hopps) writes:
  14. >rwolf@ibm.net wrote:
  15. >> In <VA.00000053.00cdab05@fred>, Frederic LACHASSE
  16. >> <lachass@worldnet.fr> writes:
  17. >> >In article <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM>, borisb@sd.znet.com 
  18. >> >(Boris Burtin) wrote:
  19. >> >> 
  20. >> >> I have noticed that a copy constructor and operator= perform pretty
  21. >> >> much the same function.  The code I wrote for my class simply copies
  22. >> >> each member variable from one class to the other.
  23. >> >> 
  24. >
  25. >> A rather typical form is to have the create a "ShallowCopy" 
  26. >> function that is called from both the copy constructor and the 
  27. >> operator=.   ShallowCopy copies only the member variables 
  28. >> at the current derivation level.
  29. >
  30. >
  31. >The ShallowCopy function is not implemented here, but if it functions
  32. >as the name implies, a member which points to dynamically allocated
  33. >data would be copied by copying the pointer itself, not by creating a
  34. >new copy of the original pointed-to data.  This creates a problem with
  35. >multiple deletion and dangling pointers as one of the copies is destroyed.
  36. >--
  37. Sorry for using my-own definition of shallow copy, but I did intent 
  38. that dynamically allocated data is duplicated.  My use of shallow refers
  39. to this derivation level.
  40.